//
//  LDheartController.m
//  Gift
//
//  Created by 李迪 on 15/11/27.
//  Copyright © 2015年 dllo. All rights reserved.
//

#import "LDheartController.h"
#import "LDSqlData.h"
#import "GiftModel.h"
#import "BaseHeader.h"
#import "LDWebController.h"

@interface LDheartController ()<UITableViewDataSource,UITableViewDelegate>

@property (nonatomic, retain)UITableView *tab;
@property (nonatomic, retain)NSMutableArray *array;



@end

@implementation LDheartController

- (void)dealloc{
    [self.tab release];
    [super dealloc];
}

- (void)createrTab{
    
    self.tab = [[UITableView alloc]initWithFrame:self.view.bounds style:UITableViewStylePlain];
    self.tab.delegate = self;
    self.tab.dataSource = self;
    self.tab.rowHeight = 80.0f;
    [self.tab registerClass:[UITableViewCell class] forCellReuseIdentifier:@"tabCell"];
    [self.view addSubview:self.tab];
    [self.tab release];
    
     self.array = [[LDSqlData sharedDataBase] selecteCollect];
    
    
}



- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    
    
   return self.array.count;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"tabCell"];
    
    GiftModel *model = [self.array objectAtIndex:indexPath.row];
    cell.textLabel.text = model.title;
    [cell.imageView sd_setImageWithURL:[NSURL URLWithString:model.cover_image_url]];

    return cell;
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    GiftModel *model = [self.array objectAtIndex:indexPath.row];
    LDWebController *web = [[LDWebController alloc]init];
    web.model = model;
    web.str = model.content_url;
    [self.navigationController pushViewController:web animated:YES];

    [model release];
    [web release];
    
}










- (void)viewDidLoad { 
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    [self createrTab];
    self.array = [[LDSqlData sharedDataBase] selecteCollect];
    self.title = @"收藏";
    [self.navigationController.navigationBar setTitleTextAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:20.], NSForegroundColorAttributeName:[UIColor colorWithRed:1.000 green:1.00 blue:1.000 alpha:1.000]}];
    [self.navigationController.navigationBar setTintColor:[UIColor whiteColor]];
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
